package com.ysd.lis.service.lab.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.common.Result;
import com.ysd.lis.entity.bac.BacGermDict;
import com.ysd.lis.entity.lab.LabTransResult;
import com.ysd.lis.mapper.lab.LabTransResultMapper;
import com.ysd.lis.request.TransResultDto;
import com.ysd.lis.service.lab.LabTransResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 结果二次处理 服务实现类
 * </p>
 *
 * @author HuaiXing
 * @since 2024-01-20
 */
@Service
public class LabTransResultServiceImpl extends ServiceImpl<LabTransResultMapper, LabTransResult> implements LabTransResultService {

    @Autowired
    LabTransResultMapper labTransResultMapper;

    @Override
    public Result getTransResult(String itemNo,String rptGroup) {
        if (StringUtils.isBlank(rptGroup)){
            return Result.succ(1, "查询成功", new ArrayList<>());

        }
        LambdaQueryWrapper<LabTransResult> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LabTransResult::getDelFlag, 0).eq(LabTransResult::getItemNo, itemNo).eq(LabTransResult::getRptGroup, rptGroup);
        List<LabTransResult> labTransResults = labTransResultMapper.selectList(queryWrapper);
        return Result.succ(1, "查询成功", labTransResults);
    }

    @Override
    public Result saveOrUpdateTransResult(TransResultDto dto) {
        List<LabTransResult> labTransResultList = dto.getLabTransResultList();
        boolean b = this.saveOrUpdateBatch(labTransResultList);
        if (b) {
            return Result.succ(1, "成功", null);
        } else {
            return Result.fail(400, "失败", "");
        }
    }

    @Override
    public Result batchDeleteTransResult(TransResultDto dto) {
        List<LabTransResult> labTransResultList = dto.getLabTransResultList();

        List<String> ids = labTransResultList.stream().map(LabTransResult::getId).collect(Collectors.toList());
        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }
}
